package ru.spb.nicetu.altx.mnemo.utils.xmlsettings;

import java.io.InputStream;
import java.util.Collection;
import java.util.Map;

public abstract class ABaseDomSimpleSettingsDocument implements ISimpleSettingsDocument {


  private static String GROUP_TYPE = "-";

  private ISettingsDocument m_settingDoc;
  public ABaseDomSimpleSettingsDocument() {
    m_settingDoc = createSettingDoc();
  }

  abstract protected ISettingsDocument createSettingDoc();



  @Override
  public boolean addElement(String groupId, String elementId,
                            Map<String, String> properties) {
    return m_settingDoc.addElement(groupId, GROUP_TYPE, elementId, properties);
  }

  @Override
  public boolean addGroup(String groupId, Map<String, String> properties) {
    return m_settingDoc.addGroup(groupId, GROUP_TYPE, properties);
  }

  @Override
  public Collection<String> getAllGroups() {
    return m_settingDoc.getGroups(GROUP_TYPE);
  }

  @Override
  public String getElementProperty(String groupId, String elementId, String key) {
    return m_settingDoc.getElementProperty(groupId, GROUP_TYPE, elementId, key);
  }

  @Override
  public Collection<String> getGroupElements(String groupId) {
    return m_settingDoc.getGroupElements(groupId, GROUP_TYPE);
  }

  @Override
  public String getGroupProperty(String groupId, String key) {
    return m_settingDoc.getGroupProperty(groupId, key);
  }

  @Override
  public boolean isGroupExist(String groupId) {
    return m_settingDoc.isGroupExist(groupId, GROUP_TYPE);
  }

  @Override
  public boolean removeElement(String groupId, String elementId) {
    return m_settingDoc.removeElement(groupId, GROUP_TYPE, elementId);
  }

  @Override
  public boolean removeGroup(String groupId) {
    return removeGroup(groupId);
  }

  @Override
  public void setElementProperty(String groupId, String elementId, String key,
                                 String value) {
    m_settingDoc.setElementProperty(groupId, GROUP_TYPE, elementId, key, value);
  }

  @Override
  public void setGroupProperty(String groupId, String key, String value) {
    m_settingDoc.setGroupProperty(groupId, GROUP_TYPE, key, value);
  }

  @Override
  public InputStream toStream() {
    return m_settingDoc.toStream();
  }

}
